/****************************************************************
 * Programa que gera uma Base de Dados	baseados na foórmula de *
 * Peter Schattner em Searching for RNA genes using				* 
 * base-composition	statistics.									*
 * 																*
 * Autora: Cristina Teixeira de Oliveira						*
 * e-mail: cto@icmc.usp.br										*
 * *************************************************************/

#include <stdio.h> 
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define TAM_SEQ 50
#define QTDE_SEQ 10

int main(int argc, char *argv[]) {
	int i, j, base, G, C, A, T, dnGC;
	char sequencia[TAM_SEQ+1];
	float GC, pGC; 
        
	/* inicializar o gerador de números aleatórios */
	srand(time(0));
		
	for (j=0; j<QTDE_SEQ; j++) {
		printf("\n***** SEQUENCIA %d ******\n", j);
		G=0; C=0; A=0; T=0; dnGC=0;	
	 	for (i=0; i<TAM_SEQ; i++) {
			/* para gerar números aleatórios de 0 a 50 */
			base = rand() % 4;
			if (base == 0){ 
				sequencia[i]='G';
				G++;
			}else if (base == 1) {
				sequencia[i]='C';
				C++;
				if ((i>0)&&(sequencia[i-1]=='G')) dnGC++;
			}else if (base == 2){
				sequencia[i]='A';
				A++;
			}else if (base == 3){
				sequencia[i]='T';
				T++;
			}
			//printf("\n%s ", sequencia);
	 	}
	 	sequencia[TAM_SEQ]='\0';
		printf("\n%s ", sequencia);
		printf("\nG=%d\tC=%d\tA=%d\tT=%d\tdnGC=%d", G, C, A, T, dnGC);
		
		GC = (float)((float)(100*(G+C))/(float)(A+C+G+T));
		pGC = 0;
		if (G*C != 0) pGC = (float)((float)(TAM_SEQ*dnGC)/(float)(G*C));
		
		printf("\n(G,C)\%=%f \t p(GC)=%f\n", GC, pGC); 
	}
		
	return 0;	
}